package com.example.sports_meet.athlete;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.sports_meet.MyDbHelper;
import com.example.sports_meet.R;

public class Athlete_InsertMessage extends AppCompatActivity {

    private EditText editName, editSex, editAge, editCompion, editId;
    private Button btnSub;
    private ImageView imageView;

    MyDbHelper myDbHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_athlete_insert_message);
        editName = (EditText) findViewById(R.id.editname);
        editSex = (EditText) findViewById(R.id.editsex);
        editAge = (EditText) findViewById(R.id.editage);
        editCompion = (EditText) findViewById(R.id.editbs);
        editId = (EditText) findViewById(R.id.editid);
        imageView = (ImageView) findViewById(R.id.imageView2);
        btnSub = (Button) findViewById(R.id.btnsub);

        myDbHelper = new MyDbHelper(Athlete_InsertMessage.this, "db", null, 2);
        btnSub.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SQLiteDatabase sqLiteDatabase;
                String name = editName.getText().toString();
                Integer age = Integer.valueOf(editAge.getText().toString());
                String sex = editSex.getText().toString();
                String Eno = editCompion.getText().toString();
                String no = editId.getText().toString();
                //sqLiteDatabase = managerAthleteHelper.getWritableDatabase();
                sqLiteDatabase = myDbHelper.getWritableDatabase();
                ContentValues values = new ContentValues();
                values.put("ano", no);
                values.put("aname", name);
                values.put("asex", sex);
                values.put("aage", age);
                values.put("assort", "学生");
                sqLiteDatabase.insert("athlete", null, values);
                ContentValues values1 = new ContentValues();
                values1.put("ano", no);
                values1.put("eno", Eno);
                sqLiteDatabase.insert("signup", null, values1);
                Toast.makeText(Athlete_InsertMessage.this, "注册成功", Toast.LENGTH_LONG).show();
                sqLiteDatabase.close();
            }
        });
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                imageView.setImageResource(R.mipmap.genggai);
            }
        });
    }
}